package com.chat.login.controller;

import com.chat.common.vo.R;
import com.chat.login.domain.dto.CaptchaDTO;
import com.chat.login.domain.vo.CaptchaVO;
import com.chat.login.domain.vo.VoucherVO;
import com.chat.login.service.CaptchaService;

import jakarta.validation.constraints.Email;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 验证码
 */
@RestController
@Slf4j
//参数验证注解
@Validated
@RequestMapping("/auth/captcha")
public class CaptchaController {

    @Autowired
    CaptchaService captchaService;

    /**
     * 发送邮箱验证码
     * @param email
     * @return
     */
    @GetMapping("/mailCaptcha")
    public R<CaptchaVO> mailCaptcha(@RequestParam @Email(message = "邮箱格式错误") String email){
        return R.succeed(captchaService.sendTextMailMessage(email));
    }

    /**
     * 验证邮箱验证码
     * @param captchaDTO
     * @return
     */
    @PostMapping("/validate_mailCaptcha")
    public R<VoucherVO> validateMailCaptcha(@RequestBody CaptchaDTO captchaDTO){
        return captchaService.validateMailCaptcha(captchaDTO);
    }
}
